class LinkedNode:
    def __init__(self, val):
        self.val = val
        self.next = None


def insert_node(n0, P):
    n1 = n0.next
    P.next = n1
    n0.next = P


def remove(n0):
    if not n0.next:
        P = n0.next
        n1 = P.next
        n0.next = n1


def access(head, index):
    for _ in range(index):
        if not head:
            return None
        head = head.next
    return head


def find(head, target):
    index = 0
    while head:
        if head.val == target:
            return index
        head = head.next
        index += 1
    return -1


if __name__ == '__main__':
    # 初始化链表 1 -> 3 -> 2 -> 5 -> 4
    # 初始化各个节点
    n0 = LinkedNode(1)
    n1 = LinkedNode(3)
    n2 = LinkedNode(2)
    n3 = LinkedNode(5)
    n4 = LinkedNode(4)

    # 构建节点之间的引用
    n0.next = n1
    n1.next = n2
    n2.next = n3
    n3.next = n4

    p = LinkedNode(0)
    insert_node(n0, p)

    remove(n0)

    node = access(n0, 3)
    # print(node.val)

    # 实例化0到9的10个节点并按从小到大连接
    head = LinkedNode(0)  # 头节点为0
    current = head

    # 从1开始创建后续节点并连接
    for i in range(1, 10):
        current.next = LinkedNode(i)
        current = current.next  # 移动到下一个节点

    # 验证链表（遍历输出所有节点值）
    current = head
    while current:
        print(current.val, end=" -> ")
        current = current.next
    print("None")